#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

struct Node {
  int val;
  int sum;
  int ch[4];
} tr[N];
int tot;
int newnode() {
  ++tot;
  tr[tot].val = tr[tot].sum = 0;
  rep(i, 0, 3) tr[tot].ch[i] = 0;
  return tot;
}
int build_tree() {
  char c;
  cin >> c;
  int p = newnode();
  if (c == 'f')
    tr[p].val = 1;
  else if (c == 'e')
    tr[p].val = 0;
  else {
    tr[p].val = -1;
    rep(i, 0, 3) tr[p].ch[i] = build_tree();
  }
  return p;
}
int merge(int p1, int p2) {
  if (tr[p1].val == 1) return p1;
  if (tr[p2].val == 1) return p2;
  if (tr[p1].val == 0) return p2;
  if (tr[p2].val == 0) return p1;
  rep(i, 0, 3) tr[p1].ch[i] = merge(tr[p1].ch[i], tr[p2].ch[i]);
  return p1;
}
void dfs(int p, int area) {
  if (tr[p].val != -1) {
    tr[p].sum = tr[p].val * area;
    return;
  }
  tr[p].sum = 0;
  rep(i, 0, 3) {
    dfs(tr[p].ch[i], area / 4);
    tr[p].sum += tr[tr[p].ch[i]].sum;
  }
}
void solve() {
  tot = 0;
  int root1 = build_tree();
  int root2 = build_tree();
  int root = merge(root1, root2);
  dfs(root, 32 * 32);
  cout << "There are " << tr[root].sum << " black pixels." << endl;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}